package com.topsun.posclient.finance.view;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableItem;

import com.topsun.posclient.finance.entity.FinanceEntity;


public class FinaceCellModeifier implements ICellModifier {

	private TableViewer tv;
	
	public FinaceCellModeifier(TableViewer tv){
		this.tv=tv;
	}
	
	@Override
	public boolean canModify(Object element, String property) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public Object getValue(Object element, String col) {
		FinanceEntity o=(FinanceEntity)element;
		if(col.equals("0"))
		{
			return "";
		}
		if(col.equals("1"))
		{
			return o.getJiesuan();
		}
		if(col.equals("2"))
		{
			return o.getYingfu();
		}
		if(col.equals("3"))
		{
			return o.getYingshou();
		}
		if(col.equals("4"))
		{
			return o.getYingpos();
		}
		if(col.equals("5"))
		{
			return o.getYingposmoney();
		}
		if(col.equals("6"))
		{
			return o.getBank();
		}
		if(col.equals("7"))
		{
			return o.getZhanghao();
		}
		if(col.equals("8")){
			o.getBeizhu();
		}
		
		return null;
	}

	@Override
	public void modify(Object element, String property, Object value) {
		// TODO Auto-generated method stub
		TableItem item=(TableItem)element;
		FinanceEntity fin=(FinanceEntity)item.getData();
		if(property.equals("1")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setJiesuan(newValue);
		}
		else if(property.equals("2")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setYingfu(newValue);
		}
		else if(property.equals("3")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setYingshou(newValue);
		}
		else if(property.equals("4")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setYingpos(newValue);
		}
		else if(property.equals("5")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setYingposmoney(newValue);
		}
		else if(property.equals("6")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setBank(newValue);
		}
		else if(property.equals("7")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setZhanghao(newValue);
		}
		else if(property.equals("8")){
			String newValue=(String)value;
			if(newValue.equals("")){
				return;
			};
			fin.setBeizhu(newValue);
		}
		else{
			return;
		}
		tv.update(0, null);
	}

}
